var t = require("../../../../../../@babel/runtime/helpers/objectSpread2"), e = getApp();

Component({
    properties: {
        keywork: {
            type: null
        },
        memberId: {
            type: null
        }
    },
    data: {
        strUrl: "plugin.wechat-chat-sidebar.frontend.controller.customer.customer.get-member-list",
        workConfig: {
            client: "work",
            type: 17
        },
        agent_data: [],
        level_tab: [],
        my_referral: {},
        customerLevel: "level1",
        json: {
            relationLevel: 1,
            keyword: "",
            page: 1
        },
        loading: !1,
        finished: !1
    },
    lifetimes: {
        attached: function() {
            this.initData(), this.getData();
        }
    },
    methods: {
        search: function(t) {
            this.setData({
                "json.keyword": t.detail,
                "json.page": 1,
                loading: !1,
                finished: !1
            }), this.getData();
        },
        loadMore: function() {
            this.getData();
        },
        initData: function() {
            this.data.json = {
                relationLevel: 1,
                keyword: "",
                page: 1
            }, this.setData({
                customerLevel: "level1",
                finished: !1,
                loading: !1
            });
        },
        changeLevel: function(t) {
            console.log(t);
            var e = 0;
            switch (t.detail.name) {
              case "level1":
                e = 1;
                break;

              case "level2":
                e = 2;
            }
            this.setData({
                "json.page": 1,
                "json.keyword": "",
                "json.relationLevel": e,
                finished: !1,
                loading: !1
            }), this.getData();
        },
        getData: function() {
            var a = this;
            if (!this.finished || !this.loading) {
                this.loading = !0;
                var s = {};
                "customer" == this.data.keywork ? (this.data.strUrl = "plugin.customer-center.frontend.controllers.customer.get-member-list", 
                this.data.json.member_id = this.data.memberId, s = t({}, this.data.json)) : (this.data.strUrl = "plugin.wechat-chat-sidebar.frontend.controller.customer.customer.get-member-list", 
                s = t(t({}, this.data.workConfig), this.data.json));
                var n = e.getNetAddresss(this.data.strUrl);
                e._postNetWork({
                    url: n,
                    data: s,
                    success: function(t) {
                        var e = t.data;
                        if (1 == e.result) {
                            a.setData({
                                my_referral: e.data.my_referral,
                                level_tab: e.data.my_agent.json
                            });
                            var s = e.data.agent_data.json;
                            if ((a.data.json.page >= s.last_page || s.data.length < s.per_page) && a.setData({
                                finished: !0
                            }), e.data.agent_data && e.data.agent_data.json) {
                                var n = e.data.agent_data.json.data;
                                a.setData({
                                    agent_data: a.data.json.page > 1 ? a.data.agent_data.concat(n) : n
                                });
                            }
                        } else wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                });
            }
        }
    }
});